<template>
  <div class="rating-select">
    <div class="rating-type">
      <div class="btn all" @click="select(2)" :class="{active:selectType === 2}">
        <span>{{desc.all}}</span>
        <span class="num">{{ratings.length}}</span>
      </div>
      <div class="btn positive" @click="select(0)" :class="{active:selectType === 0}">
        <span>{{desc.positive}}</span>
        <span class="num">{{positives.length}}</span>
      </div>
      <div class="btn negative" @click="select(1)" :class="{active:selectType === 1}">
        <span>{{desc.negative}}</span>
        <span class="num">{{negatives.length}}</span>
      </div>
    </div>
    <div class="switch" :class="{active: onlyContent}">
      <i class="icon-check_circle" @click="toggleContent"></i>
      <span class="text">只看有内容的评价</span>
    </div>
  </div>
</template>

<script>
const POSITIVE = 0
const NEGATIVE = 1
const ALL = 2
export default {
  props: {
    ratings: {
      type: Array,
      default() {
        return []
      }
    },
    selectType: {
      type: Number,
      default: ALL
    },
    onlyContent: {
      type: Boolean,
      default: false
    },
    desc: {
      type: Object,
      default() {
        return {
          all: '全部',
          positive: '满意',
          negative: '不满意'
        }
      }
    }
  },

  methods: {
    select(type) {
      this.$emit('select', type)
    },
    toggleContent() {
      this.$emit('toggleContent')
    }
  },
  computed: {
    negatives() {
      return this.ratings.filter(item => item.rateType === NEGATIVE)
    },

    positives() {
      return this.ratings.filter(item => item.rateType === POSITIVE)
    }
  }
}
</script>

<style scoped lang="stylus">
.rating-select {
  .rating-type {
    margin: 0.24rem 0.38rem 0;
    padding-bottom: 0.36rem;
    border-bottom: 1px solid rgba(7, 17, 27, 0.1);

    .btn {
      display: inline-block;
      height: 0.32rem;
      line-height: 0.32rem;
      padding: 0.16rem 0.24rem;
      border-radius: 0.04rem;
      align-content: center;
      font-size: 0.24rem;
      background-color: rgb(0, 160, 220);
      margin-right: 0.16rem;
      color: rgb(77, 85, 93);

      &.active {
        color: #fff;
      }

      &:last-child {
        margin-right: 0;
      }

      &.positive {
        background-color: rgba(0, 160, 220, 0.2);

        &.active {
          background-color: rgb(0, 160, 220);
        }
      }

      &.negative {
        background-color: rgba(77, 85, 93, 0.2);

        &.active {
          background-color: rgb(77, 85, 93);
        }
      }

      .num {
        font-size: 0.16rem;
        margin-left: 0.04rem;
      }
    }
  }

  .switch {
    padding: 0.24rem 0.36rem;
    border-bottom: 1px solid rgba(7, 17, 27, 0.1);
    color: rgb(147, 153, 159);
    line-height: 0.48rem;
    font-size: 0;

    &.active {
      .icon-check_circle {
        color: #00c850;
      }
    }

    .icon-check_circle {
      vertical-align: -0.1rem;
      font-size: 0.48rem;
      margin-right: 0.08rem;
    }

    .text {
      font-size: 0.28rem;
    }
  }
}
</style>
